﻿using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using QuickPrompt.DataAccess;
using QuickPrompt.DomainModel;
using QuickPrompt.DomainModel.Identity;
using QuickPrompt.Test.IntegrationTests;
using RedandBlue.RepositoryPattern.DataContext;
using RedandBlue.RepositoryPattern.EF6;
using RedandBlue.RepositoryPattern.Infrastructure;
using RedandBlue.RepositoryPattern.Repositories;
using RedandBlue.RepositoryPattern.UnitOfWork;

namespace QuickPrompt.Test
{
    [TestFixture]
    public class QuickNoteTest
    {
        [TestFixtureSetUp]
        public void Initialize()
        {
            Utility.CreateSeededTestDatabase();
        }

        [Test(Description="First Reminder")]
        [TestCase("hbopuri")]
        public void CreateNote(string userName)
        {


            var prompts = new List<Prompt>();
            prompts.Add(new Prompt());

            // Create new Reminder
            using (IDataContextAsync context = new QuickPromptContext())
            using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
            {
                var user = unitOfWork.Repository<User>()
                    .Query(x => x.UserName.Equals(userName, StringComparison.OrdinalIgnoreCase))
                    .Select()
                    .FirstOrDefault();
                Assert.IsNotNull(user);
                var reminder = new QuickNote
                {
                    Name = "Test Reminder",
                    Description = "Creating this reminder from Test project",
                    IsActive = true,
                    IsDeleted = false,
                    StartDateUtc = DateTime.UtcNow,
                    DateCreatedUtc = DateTime.UtcNow,
                    EndDateUtc = DateTime.UtcNow.AddMonths(10),
                    UserGuid = user.Id,
                    LastUpdatedUtc = DateTime.UtcNow,
                    LastActivityIpAddress = null,
                    UpdatedByUserId = 1,
                    Prompts = prompts,
                    ObjectState = ObjectState.Added
                };

                IRepositoryAsync<QuickNote> reminderRepository = new Repository<QuickNote>(context, unitOfWork);
                reminderRepository.Insert(reminder);
                unitOfWork.SaveChanges();
            }
        }
    }
}
